package com.medical.config;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;


/**
 * 全局常量配置
 * @author Mr.xucb
 * @version 1.0
 */
public final class SystemContext {
	
	private static final String SITE_WIDE_SECRET = "GXUWZ_0774_KEY";  
	private static final PasswordEncoder encoder = new StandardPasswordEncoder(SITE_WIDE_SECRET); 
	
	/**
	 * 密码加密
	 * @param rawPasswd 需要加密的密码
	 * @return
	 */
	public static String passwdEncryption(String rawPasswd){
		//System.out.println("rawPasswd="+rawPasswd);
		String str = encoder.encode(rawPasswd);
		return str;
	}

	/**
	 * 密码校验
	 * @param password 数据库保存的加密的密码
	 * @return true = 通过，fasle=失败
	 */
	public static boolean passwdDecryption(String rawPasswd, String password){
//		System.out.println("rawPasswd="+rawPasswd);
//		System.out.println("password="+password);
		boolean isT = false;
		try {
			isT = encoder.matches(rawPasswd, password);
			//isT = encoder.matches("123",passwdEncryption("123"));
			//System.out.println("密码匹配--完毕"+isT);
		} catch (Exception e) {
			System.out.println("密码匹配："+e);
		}
		return isT;
	}
	
}
